package Thread.Thread05;

import ch.qos.logback.core.joran.action.ConversionRuleAction;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadTest {

    /*

    public ThreadPoolExecutor(int corePoolSize,
                              int maximumPoolSize,
                              long keepAliveTime,
                              TimeUnit unit,
                              BlockingQueue<Runnable> workQueue,
                              ThreadFactory threadFactory,
                              RejectedExecutionHandler handler)

     */
    public static void main(String[] args) {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(3, 5, 8, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(4), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());;

        Runnable runnable = new MyRunnable();
        pool.execute(runnable);//线程会自动创建一个新线程，自动处理这个任务，自动执行的！
        pool.execute(runnable);//线程会自动创建一个新线程，自动处理这个任务，自动执行的！
        pool.execute(runnable);//线程会自动创建一个新线程，自动处理这个任务，自动执行的！
        pool.execute(runnable);//复用前面的核心线程
        pool.execute(runnable);//复用前面的核心线程
        pool.execute(runnable);//复用前面的核心线程
        pool.execute(runnable);//复用前面的核心线程
        //到了创建临时线程的时机了
        pool.execute(runnable);
        pool.execute(runnable);
        pool.execute(runnable);


//        pool.shutdown();//等着线程池的任务全部执行完毕后，再关闭线程池
//        pool.shutdownNow();//立即关闭线程，不顾那任务是否执行完

    }
}
